local game = require "club.threecard.jacksorbetter"

local poker = game.ui.element(game.pokerlib.core.poker)

function poker:ctor()
    self.res = "club.threecard.jacksorbetter/ui/ingame.b:poker"
    self.click_handler = nil;
    self.is_forbid = false
end

function poker:flip(poker_data, callback, time_lenght)
    time_lenght = time_lenght or 0.5;
    self.transform:DOScaleX(0, time_lenght/2)
    :OnComplete(function()
        self:set_data(poker_data);
        self.transform:DOScaleX(1, time_lenght/2)
        :OnComplete(function()
            callback();
         end)
    end)
end

function poker:on_click()
    if self.is_forbid then
        return
    end

    if self.click_handler then
        self:click_handler();
        self.selected = true
    end
end

function poker:select()
    if self.is_forbid then
        return
    end

    self:will_select(false);

    if self.click_handler then
        return
    end

    if self.selected then
        self:unselect();
    else
        self.selected = true;
        self.select_flag2:SetActive(true);
    end
end

function poker:unselect()
    if self.is_forbid then
        return
    end

    self:will_select(false);
    self.selected = false;
    self.select_flag2:SetActive(false);
end

function poker:will_select(b)
    if self.is_forbid then
        return
    end

    self:super("will_select", b)
end

function poker:forbid()
    self.click_handler = nil;
end

function poker:gray(b)
    self.select_flag.gameObject:SetActive(b)
end

function poker:forbid2(b)
    self.is_forbid = b
end

return poker